#include <oatpp-websocket/ConnectionHandler.hpp>
#include <oatpp-websocket/WebSocket.hpp>
#include "RemoteHandle.h"

class WSMonitorEvent: public wxEvent
{
public:
    WSMonitorEvent(wxEventType eventType, int winid, int status)
        : wxEvent(winid, eventType),status(status)
    {}
 
    // accessors
    int GetStatus() const {return status;}
    // implement the base class pure virtual
    virtual wxEvent *Clone() const { return new WSMonitorEvent(*this); }
 
private:
    const int status;
};

wxDECLARE_EVENT(EVT_WSMONITOR,WSMonitorEvent);
typedef void (wxEvtHandler::*WSMonitorEventFunc)(WSMonitorEvent&);
#define WSMonitorEventHandler(func) wxEVENT_HANDLER_CAST(WSMonitorEventFunc, func)

class WSMonitor : public oatpp::websocket::WebSocket::Listener
{
private:
    std::mutex& m_writeMutex;
    oatpp::data::stream::BufferOutputStream m_messageBuffer;
    wxEvtHandler* _evtHandler;
    RemoteHandle* _remoteHandle;
public:
    WSMonitor(std::mutex& writeMutex,wxEvtHandler* evtHandler,RemoteHandle* remoteHandler);
    void onPing(const WebSocket& socket, const oatpp::String& message) override;
    void onPong(const WebSocket& socket, const oatpp::String& message) override;
    void onClose(const WebSocket& socket, v_uint16 code, const oatpp::String& message) override;
    void readMessage(const WebSocket& socket, v_uint8 opcode, p_char8 data, oatpp::v_io_size size) override;
};